﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/List2.Master" AutoEventWireup="true" CodeBehind="RolePermList.aspx.cs" Inherits="Honestysoft.Baseframework.WebUI.SystemManage.Permission.RolePermList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<%--<script type="text/javascript" src="../../Scripts/jquery-1.6.min.js"></script>--%>
    <script language="javascript" type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <link href="../../Styles/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/control.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        $(function () {
            $('#tResource').treegrid({
                nowrap: false,
                rownumbers: true,
                animate: true,
                collapsible: true,
                url: 'JSON/RolePerm.ashx?RoleID=<%=Request.QueryString["ID"] %>',
                method:"POST",
                idField: 'ID',
                treeField: 'FuncName',
//                frozenColumns: [[
//	                { title: 'FuncName', field: 'FuncName', width: 200,
//	                    formatter: function (value) {
//	                        return '<span style="color:red">' + value + '</span>';
//	                    }
//	                }
//				]],
                columns: [[
					{ field: 'FuncName', title: '功能名称', width: 250 },
					<%=GetOperationColumn() %>
				]],
                onBeforeLoad:function(row,param){
					$(this).treegrid('options').url = 'JSON/RolePerm.ashx?RoleID=<%=Request.QueryString["ID"] %>';
//					if (row){
//						$(this).treegrid('options').url = 'treegrid_subdata.json';
//					} else {
//						$(this).treegrid('options').url = 'treegrid_data.json';
//					}
				}
            });
        });
        function checkedChange(chk){
            var newItem = document.getElementById("newItems");
            var delItem = document.getElementById("delItems");
            var value=chk.name+"|"+chk.value;
            if(chk.checked){
                //当前选中，如果在删除列表里面有，则移除，否则，添加到新增列表中
                if(optionExists(delItem,value)){
                    Remove(delItem,value);
                }
                else{
                    AddNoIn(newItem,value,value);
                }
            }
            else{
                //当前没有选中，如果新增列表里面有，则移除，否则，添加到删除列表中
                if(optionExists(newItem,value)){
                    Remove(newItem,value);
                }
                else{
                    AddNoIn(delItem,value,value);
                }
            }
        }
        function AddNoIn(obj,text,value){
            if(!optionExists(obj,value)){
                obj.add(document.createElement("OPTION")); 
                obj.options[obj.options.length-1].text=text; 
                obj.options[obj.options.length-1].value=value;
            }
        }
        function Remove(obj,value){
            for(var i=obj.options.length-1;i>=0;i--){
                if(obj.options[i].value == value){
                    obj.options.remove(i);
                    break;
                }        
            }
        }
    //检查obj列表框中是否已经存在选项opt   
    function optionExists(obj,value){   
        var length = obj.options.length;   
        for(var i=0;i<length;i++){   
            if(obj.options[i].value == value) //如果一个选项的值和文本与给定的选项相同，则表明存在。   
                return true;   
        }   
        return false; //不存在   
    }
    function checkSave(){
        var newItem = document.getElementById("newItems");
        var delItem = document.getElementById("delItems");
        if(newItem.options.length == 0 && delItem.options.length == 0){
            alert("当前没有修改过任何项，不需要进行此操作！");
            return false;
        }
        var newStr="",delStr="";
        for(var i=0;i<newItem.options.length;i++){
            if(newStr != ""){
                newStr += ",";
            }
            newStr += newItem.options[i].value;
        }
        for(var i=0;i<delItem.options.length;i++){
            if(delStr != ""){
                delStr += ",";
            }
            delStr += delItem.options[i].value;
        }
        document.getElementById("<%=hidNew.ClientID %>").value = newStr;
        document.getElementById("<%=hidDelete.ClientID %>").value = delStr;
        return true;
    }
    function SelectAll(){
        var arrCheckbox=document.getElementsByTagName("input");
        for(var i=0;i<arrCheckbox.length;i++)   
          {   
              var obj=arrCheckbox[i];   
              if(obj.type=="checkbox")   
              {   
                   if(!obj.checked){
                       obj.checked = true;
                        checkedChange(obj)
                    }
              }   
          }   
    }
    function UnSelectAll(){
        var arrCheckbox=document.getElementsByTagName("input");
        for(var i=0;i<arrCheckbox.length;i++)   
          {   
              var obj=arrCheckbox[i];   
              if(obj.type=="checkbox")   
              {   
                   if(obj.checked){
                       obj.checked = false;
                        checkedChange(obj)
                    }
              }   
          }   
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="button_area">
        <input type="button" id="btnSelectAll" value="全选" onclick="SelectAll();" class="btn_normal" 
			onmouseover="this.className='btn_active'" 
            onmouseout="this.className='btn_normal'" />
        <input type="button" id="btnUnSelectAll" value="全不选" onclick="UnSelectAll();" class="btn_normal" 
			onmouseover="this.className='btn_active'" 
            onmouseout="this.className='btn_normal'" />
        <asp:Button runat="server" ID="btnSave" Text="保存" CssClass="btn_normal" 
			onmouseover="this.className='btn_active'" 
            onmouseout="this.className='btn_normal'" onclick="btnSave_Click" OnClientClick="return checkSave();" />
    </div>
    <table id="tResource"></table>
    
    <select id="newItems" multiple="multiple"  style="display:none"></select>
    <select id="delItems" multiple="multiple"  style="display:none"></select>

    <asp:HiddenField ID="hidNew" runat="server" />
    <asp:HiddenField ID="hidDelete" runat="server" />
</asp:Content>
